哞叫时间

题目 哞叫时间

image-efc25277

思路分析

c6315d941c22772a526279c14937d8f7_720-a6a3d05f

代码实现

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'

const int N=20010;

vector<string> abb;
priority_queue <string,vector<string>,greater<string>> ans;

void make_abb(){
    for (char ci = 'a'; ci <= 'z'; ci++) {
        for (char cj = 'a'; cj <= 'z'; cj++) {
            if (ci != cj) {
                string pattern;
                pattern += ci;
                pattern += cj;
                pattern += cj;
                abb.push_back(pattern);
            }
        }
    }
}

int main()
{
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    make_abb();

    int n,F;cin>>n>>F;
    string S;cin>>S;
    for(auto s:abb){
        int cnt=0,flag=0;
        string t=S;
        for(int i=0;i+2<n;i++){
            string temp=t.substr(i,3);
            if(temp==s){
                t[i]=t[i+1]=t[i+2]='#';
                cnt++;
            }
        }
        for(int i=0;i+2<n;i++){
            if(t[i]=='#' || t[i+1]=='#' || t[i+2]=='#') continue;
            if((t[i]==s[0] && t[i+1]==s[1])
            || (t[i]==s[0] && t[i+2]==s[2])
            || (t[i+1]==t[i+2] && t[i+1]==s[1]))
            flag=1;
        }
        if(cnt+flag>=F){
            ans.push(s);
        }
    }
    cout<<ans.size()<<endl;
    while(!ans.empty()){
        cout<<ans.top()<<endl;
        ans.pop();
    }

    return 0;
}

同类题型

视频讲解


⬅️ 划拳 🏠 00-刷题理模型 ➡️ 哞叫时间2